package com.neusoft.neuiotms.dcam.workflow.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.neuiotms.dcam.workflow.converter.ConfirmSLConverter;
import com.neusoft.neuiotms.dcam.workflow.dto.ConfirmSLDTO;
import com.neusoft.neuiotms.dcam.workflow.model.ConfirmSL;
import com.neusoft.neuiotms.dcam.workflow.repository.ConfirmSLRepository;
import com.neusoft.neuiotms.dcam.workflow.service.ConfirmSLService;

@Service
public class ConfirmSLServiceImpl implements ConfirmSLService {

    @Autowired
    private ConfirmSLConverter confirmSLConverter;
    @Autowired
    private ConfirmSLRepository confirmSLRepository;

    @Override
    public ConfirmSLDTO create(final ConfirmSLDTO dto) {

        final ConfirmSL model = this.confirmSLConverter.toModel(dto);
        this.confirmSLRepository.save(model);
        return this.confirmSLConverter.toDTO(model);
    }

    @Override
    public Long getMainId(final String workOrderNum, final String taskId) {
        final ConfirmSL confrim = this.confirmSLRepository.findByWorkOrderNumAndTaskId(workOrderNum, taskId);
        return null != confrim ? confrim.getMainId() : null;
    }

}
